const { queryAll } = require('../../database/dbUtils')

// const getData=async (ctx:any)=>{
//   let sql=`select * from studentdata`
//   let res=await queryAll(sql)
//   // console.log(res);
//   ctx.status=200
//   ctx.body={
//     code:200,
//     msg:'获取成功',
//     result:res
//   }
// }
const getSliceData=async (ctx:any)=>{
let {college,stage,classroom,pageSize,pageNumber}=ctx.request.query
console.log(college,stage,classroom,pageSize,pageNumber);
  let sql=`select * from studentdata`
  let res=await queryAll(sql)
  //筛选数据
  let coll:any=[]
  res.forEach((item:any)=>{
    if(college==item.college){
      coll.push(item)
    }
  })
  //阶段
  let jie:any=[]
  coll.forEach((item:any)=>{
    if(stage==item.stage){
      jie.push(item)
    }
  })
  //班级
  let ban:any=[]
  jie.forEach((item:any)=>{
    if(classroom==item.class){
      ban.push(item)
    }
  })
  //截取数据
  let start=(pageNumber-1)*pageSize
  let end=Number(start+pageSize)
  let arr=ban.slice(start,end)
  // console.log(arr);
  ctx.status=200
  ctx.body={
    code:200,
    msg:'获取成功',
    result:{arr,res,ban}
  }
}
//删除数据
const studentsDel=async (ctx:any)=>{
  let {number}=ctx.request.query
  console.log(number,1);
  let sql=`delete from studentdata where number='${number}'`
  let res=await queryAll(sql)
  ctx.status=200
  ctx.body={
    code:200,
    msg:'获取成功',
    result:res
  }
}
export {
  // getData,
  getSliceData,
  studentsDel
}